import axios from "axios";
import router from "@/router";

const request = axios.create({
  baseURL: "/video", //基础路径上会携带/ziyang
  timeout: 60000, //超时的时间的设置
});
//第二步:request实例添加请求与响应拦截器
request.interceptors.request.use((config) => {
  //返回配置对象
  return config;
});

//第三步:响应拦截器
request.interceptors.response.use(
  (response) => {
    //成功回调
    if (response.data.code === 302) {
      sessionStorage.removeItem("is_front_login");
      router.push("/search");
    }
    //简化数据
    return response.data;
  },
  (error) => {
    console.log("error", error);
    return Promise.reject(error);
  }
);
//对外暴露
export default request;
